<template>
  <div>
    <el-row type="flex" justify="space-between" class="page-tools">
      <el-col class="left">
        <slot name="left">
          <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item :label='title'>
              <el-input v-model="formInline.subjectName"></el-input>
            </el-form-item>
            <el-form-item label="状态" style="margin-left:20px" v-if="show">
              <el-select v-model="formInline.state" placeholder="请选择">
                <el-option label="启用" value="1"></el-option>
                <el-option label="禁用" value="0"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button size="small" @click="clear">清除</el-button>
              <slot name="btn">
              </slot>
            </el-form-item>

          </el-form>
        </slot>
      </el-col>
      <el-col class="right" :span="6">
        <slot name="right">
          <el-row type="flex" justify="end">
            <el-button type="success" @click="add">
              {{ btn }}
            </el-button>
          </el-row>
        </slot>
      </el-col>
    </el-row>
    <el-row class="total">
      <!-- 总数 -->
      <slot>
        <span><i class="el-icon-info"></i> 数据一共{{ total }}条</span>
      </slot>
    </el-row>
  </div>
</template>

<script>
export default {
  props: {
    total: {
      default: 0,
      type: Number
    },
    btn: {
      require: true,
      type: String,
      default: '新增学科'
    },
    title: {
      require: true,
      type: String,
      default: '标签名称'
    },
    show: {
      default: false,
      type: Boolean
    }
  },
  data() {
    return {
      formInline: {
        subjectName: '',
        state: ''
      }
    }
  },
  methods: {
    search(data) {
      if (!this.formInline.state) {
        // 学科
        return data.filter(item => item.subjectName.includes(this.formInline.subjectName))
      } else {
        // 目录和标签
        return data.filter(item => (item.tagName ? item.tagName : item.directoryName).includes(this.formInline.subjectName) && item.state === parseInt(this.formInline.state))
      }
    },
    add() {
      this.$emit('showDialog', true)
    },
    clear() {
      this.formInline = { subjectName: '', state: '' }
      this.$emit('clear')
    }
  }
}
</script>

<style scoped>
.page-tools {
  margin: 0 10px;
}

.total {
  padding: 10px;
  margin-bottom: 10px;
  background-color: #f4f4f5;
  border-radius: 5px;
  color: #909399;
}

.total i {
  margin: 0 5px;
}
</style>
